package com.icss.flow.utils;

import com.icss.flow.exception.FlowException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.camunda.bpm.engine.form.FormField;

import java.util.List;
import java.util.Map;

import static oracle.jdbc.diagnostics.SecuredLogger.Attribute.CLASS_NAME;

/**
 * @author mobai
 */
@Slf4j
@AllArgsConstructor
public class FormUtils {
    /**
     * 校验表单必填项
     * @param params
     * @param formFields
     */
    public static void verifyForm(Map<String, Object> params, List<FormField> formFields) {
        for (FormField formField : formFields) {
            // 查询发起流程的表单必填项
            if (ObjectUtils.isEmpty(params.get(formField.getLabel()))) {
                log.warn("------------------>{}字段是必填项", formField.getLabel());
                throw new FlowException(formField.getLabel() + "字段是必填项");
            }
        }
    }
}
